/****************************************************************************
**
** Copyright (C) 2013 Ernesto Barragan <ernestus at gmail dot com>
**
** GNU General Public License Usage
** This file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
****************************************************************************/

#ifndef SERIALPORTSETTINGS_H
#define SERIALPORTSETTINGS_H
#include <QSettings>
#include <QSerialPort>
#include <QMap>
#include <QCoreApplication>

class SerialPortSettings
{
    Q_DECLARE_TR_FUNCTIONS( SerialPortSettings )

public:
    SerialPortSettings() ;
    ~SerialPortSettings() ;
    void save() const ;
    bool applyToPort( QSerialPort& port ) const ;

    const QMap<QSerialPort::Parity, QString>& parityToString() ;
    const QMap<QSerialPort::StopBits, QString>&  stopBitsToString() ;
    const QMap<QSerialPort::FlowControl, QString>& flowControlToString() ;

    //Wow! public data :)
    QString device;
    qint32 baudRate;
    QSerialPort::DataBits dataBits;
    QSerialPort::Parity parity;
    QSerialPort::StopBits stopBits;
    QSerialPort::FlowControl flowControl;
    //not actually a serial port setting, but...
    bool localEchoEnabled;

private:
    /* maps used by the ...toString members */
    QMap <QSerialPort::Parity, QString> m_parityStrings ;
    QMap <QSerialPort::StopBits, QString> m_stopBitsStrings ;
    QMap <QSerialPort::FlowControl, QString> m_flowControlStrings ;
};

#endif // SERIALPORTSETTINGS_H
